package com.my.imq.web.root;

import com.my.imq.web.view.BrokerLayout;
import com.vaadin.ui.Component;
import com.vaadin.ui.TabSheet;
import com.vaadin.ui.TabSheet.SelectedTabChangeEvent;
import com.vaadin.ui.TabSheet.Tab;
import com.vaadin.ui.VerticalLayout;

/**
 * @author <a href="MABDELOUHAB">MABDELOUHAB</a>
 * created 21 mai 2012
 * @since 
 * @version $Id$
 */
public class RightLayout
    extends VerticalLayout
    implements TabSheet.SelectedTabChangeListener, TabSheet.CloseHandler
{

    private TabSheet t;

    /**
    * 
    */
    public RightLayout()
    {
        t = new TabSheet();

        final Tab imqMetricsTab = t.addTab( new BrokerLayout(), "Imq Metrics" );
        imqMetricsTab.setClosable( false );

        t.addListener( this );

        t.addListener( this );
        t.setCloseHandler( this );

        addComponent( t );
    }

    /* (non-Javadoc)
     * @see com.vaadin.ui.TabSheet.CloseHandler#onTabClose(com.vaadin.ui.TabSheet, com.vaadin.ui.Component)
     */
    public void onTabClose( TabSheet tabsheet, Component tabContent )
    {
        getWindow().showNotification( "Closed tab: " + tabsheet.getTab( tabContent ).getCaption() );
        tabsheet.removeComponent( tabContent );

    }

    public void addTab( String queue )
    {

        final Tab tab = t.addTab( new BrokerLayout(), queue );
        tab.setClosable( true );
    }

    /* (non-Javadoc)
     * @see com.vaadin.ui.TabSheet.SelectedTabChangeListener#selectedTabChange(com.vaadin.ui.TabSheet.SelectedTabChangeEvent)
     */
    public void selectedTabChange( SelectedTabChangeEvent event )
    {
        TabSheet tabsheet = event.getTabSheet();
        Tab tab = tabsheet.getTab( tabsheet.getSelectedTab() );
        if ( tab != null )
        {
            getWindow().showNotification( "Selected tab: " + tab.getCaption() );
        }
    }

}